<h3 style="margin-top:20px;">Related Documents &amp; Guides:</h3>

<?php global $post, $wp_query;

	if(is_page()) {
		$theidnumber = get_the_ID() ;
	} elseif(is_product_category()) {
		$cat_obj = $wp_query->get_queried_object();
		if($cat_obj) {
			$theidnumber = $cat_obj->term_id;
		}
	} else {
		$theidnumber = get_the_ID();
	} 	

	$taxs = wp_get_post_tags($post->ID);
	$tax_ids = array();
	foreach ( $taxs as $individual_tax ) $tax_ids[] = $individual_tax->slug;
?>

<?php // GENERAL DOCUMENTS
	
	$args = array(
		'post_type' => 'document',
		'tax_query' => array(
			array(
				'taxonomy' => 'wpdr-file-tags',
				'field' => 'slug',
				'terms' => ''.$theidnumber.''
			)
		),
		'meta_query' => array(
			array(
                		'key' => 'documenttype',
                		'value' => 'General Document',
                		'compare' => '='  
			)
		)
	);

	$docs_general = new wp_query($args);

	if($docs_general->have_posts()) {
		echo '<h3 style="font-size:15px;">Related General Documents</h3>';
		echo '<ul>';
		
		while($docs_general->have_posts()) : $docs_general->the_post();
			$do_not_duplicate = $post->ID;

			echo '<li><a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></li>';

		endwhile;

		echo '</ul>';

	}
	wp_reset_query();
?>

<?php // BROCHURES
	
	$args = array(
		'post_type' => 'document',
		'tax_query' => array(
			array(
				'taxonomy' => 'wpdr-file-tags',
				'field' => 'slug',
				'terms' => ''.$theidnumber.''
			)
		),
		'meta_query' => array(
			array(
                		'key' => 'documenttype',
                		'value' => 'Brochure',
                		'compare' => '='  
			)
		)
	);

	$docs_general = new wp_query($args);

	if($docs_general->have_posts()) {
		echo '<h3 style="font-size:15px;">Related Brochures</h3>';
		echo '<ul>';
		
		while($docs_general->have_posts()) : $docs_general->the_post();
			$do_not_duplicate = $post->ID;

			echo '<li><a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></li>';

		endwhile;

		echo '</ul>';
		
	}
	wp_reset_query();
?>

<?php // DATA SHEETS
	
	$args = array(
		'post_type' => 'document',
		'tax_query' => array(
			array(
				'taxonomy' => 'wpdr-file-tags',
				'field' => 'slug',
				'terms' => ''.$theidnumber.''
			)
		),
		'meta_query' => array(
			array(
                		'key' => 'documenttype',
                		'value' => 'Data Sheet',
                		'compare' => '='  
			)
		)
	);

	$docs_general = new wp_query($args);

	if($docs_general->have_posts()) {
		echo '<h3 style="font-size:15px;">Related Data Sheets</h3>';
		echo '<ul>';
		
		while($docs_general->have_posts()) : $docs_general->the_post();
			$do_not_duplicate = $post->ID;

			echo '<li><a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></li>';

		endwhile;

		echo '</ul>';
		
	}
	wp_reset_query();
?>

<?php // INSTALLATION MANUALS
	
	$args = array(
		'post_type' => 'document',
		'tax_query' => array(
			array(
				'taxonomy' => 'wpdr-file-tags',
				'field' => 'slug',
				'terms' => ''.$theidnumber.''
			)
		),
		'meta_query' => array(
			array(
                		'key' => 'documenttype',
                		'value' => 'Installation Manual',
                		'compare' => '='  
			)
		)
	);

	$docs_general = new wp_query($args);

	if($docs_general->have_posts()) {
		echo '<h3 style="font-size:15px;">Related Installation Manuals</h3>';
		echo '<ul>';
		
		while($docs_general->have_posts()) : $docs_general->the_post();
			$do_not_duplicate = $post->ID;

			echo '<li><a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></li>';

		endwhile;

		echo '</ul>';
		
	}
	wp_reset_query();
?>

<?php // WARRANTIES
	
	$args = array(
		'post_type' => 'document',
		'tax_query' => array(
			array(
				'taxonomy' => 'wpdr-file-tags',
				'field' => 'slug',
				'terms' => ''.$theidnumber.''
			)
		),
		'meta_query' => array(
			array(
                		'key' => 'documenttype',
                		'value' => 'Warranty',
                		'compare' => '='  
			)
		)
	);

	$docs_general = new wp_query($args);

	if($docs_general->have_posts()) {
		echo '<h3 style="font-size:15px;">Related Warranties</h3>';
		echo '<ul>';
		
		while($docs_general->have_posts()) : $docs_general->the_post();
			$do_not_duplicate = $post->ID;

			echo '<li><a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></li>';

		endwhile;

		echo '</ul>';
		
	}
	wp_reset_query();
?>

<?php // SRCC OG-100 CERTIFICATIONS
	
	$args = array(
		'post_type' => 'document',
		'tax_query' => array(
			array(
				'taxonomy' => 'wpdr-file-tags',
				'field' => 'slug',
				'terms' => ''.$theidnumber.''
			)
		),
		'meta_query' => array(
			array(
                		'key' => 'documenttype',
                		'value' => 'SRCC OG-100 Certification',
                		'compare' => '='  
			)
		)
	);

	$docs_general = new wp_query($args);

	if($docs_general->have_posts()) {
		echo '<h3 style="font-size:15px;">Related SRCC OG-100 Certifications</h3>';
		echo '<ul>';
		
		while($docs_general->have_posts()) : $docs_general->the_post();
			$do_not_duplicate = $post->ID;

			echo '<li><a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></li>';

		endwhile;

		echo '</ul>';
		
	}
	wp_reset_query();
?>

<?php // SRCC OG-300 CERTIFICATION
	
	$args = array(
		'post_type' => 'document',
		'tax_query' => array(
			array(
				'taxonomy' => 'wpdr-file-tags',
				'field' => 'slug',
				'terms' => ''.$theidnumber.''
			)
		),
		'meta_query' => array(
			array(
                		'key' => 'documenttype',
                		'value' => 'SRCC OG-300 Certification',
                		'compare' => '='  
			)
		)
	);

	$docs_general = new wp_query($args);

	if($docs_general->have_posts()) {
		echo '<h3 style="font-size:15px;">Related SRCC OG-300 Certifications</h3>';
		echo '<ul>';
		
		while($docs_general->have_posts()) : $docs_general->the_post();
			$do_not_duplicate = $post->ID;

			echo '<li><a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></li>';

		endwhile;

		echo '</ul>';
		
	}
	wp_reset_query();
?>

<?php // TECHNICAL DRAWINGS
	
	$args = array(
		'post_type' => 'document',
		'tax_query' => array(
			array(
				'taxonomy' => 'wpdr-file-tags',
				'field' => 'slug',
				'terms' => ''.$theidnumber.''
			)
		),
		'meta_query' => array(
			array(
                		'key' => 'documenttype',
                		'value' => 'CAD File',
                		'compare' => '='  
			)
		)
	);

	$docs_general = new wp_query($args);

	if($docs_general->have_posts()) {
		echo '<h3 style="font-size:15px;">Related CAD Files &amp; Technical Drawings</h3>';
		echo '<ul>';
		
		while($docs_general->have_posts()) : $docs_general->the_post();
			$do_not_duplicate = $post->ID;

			echo '<li><a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></li>';

		endwhile;

		echo '</ul>';
		
	}
	wp_reset_query();
?>

<?php // PIPING DIAGRAMS
	
	$args = array(
		'post_type' => 'document',
		'tax_query' => array(
			array(
				'taxonomy' => 'wpdr-file-tags',
				'field' => 'slug',
				'terms' => ''.$theidnumber.''
			)
		),
		'meta_query' => array(
			array(
                		'key' => 'documenttype',
                		'value' => 'Piping Diagram',
                		'compare' => '='  
			)
		)
	);

	$docs_general = new wp_query($args);

	if($docs_general->have_posts()) {
		echo '<h3 style="font-size:15px;">Related Piping Diagrams</h3>';
		echo '<ul>';
		
		while($docs_general->have_posts()) : $docs_general->the_post();
			$do_not_duplicate = $post->ID;

			echo '<li><a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></li>';

		endwhile;

		echo '</ul>';
		
	}
	wp_reset_query();
?>

<?php // CASE STUDIES
	
	$args = array(
		'post_type' => 'document',
		'tax_query' => array(
			array(
				'taxonomy' => 'wpdr-file-tags',
				'field' => 'slug',
				'terms' => ''.$theidnumber.''
			)
		),
		'meta_query' => array(
			array(
                		'key' => 'documenttype',
                		'value' => 'Case Study',
                		'compare' => '='  
			)
		)
	);

	$docs_general = new wp_query($args);

	if($docs_general->have_posts()) {
		echo '<h3 style="font-size:15px;">Related Case Studies</h3>';
		echo '<ul>';
		
		while($docs_general->have_posts()) : $docs_general->the_post();
			$do_not_duplicate = $post->ID;

			echo '<li><a href="'.get_permalink().'" target="_blank">'.get_the_title().'</a></li>';

		endwhile;

		echo '</ul>';
		
	}
	wp_reset_query();
?>